#ifndef EPOLL_HPP
#define EPOLL_HPP
#include <sys/epoll.h>
#include "log.hpp"
#define MAXSIZE 100 // 最大连接数
using namespace LOG;
class Epoll
{
public:
    Epoll()
    {
        int epfd = epoll_create(1);
        if(epfd < 0)
        {
            lg(FATAL,"epoll create fail");
            exit(0);
        }
        _epfd = epfd;
    }
    void Add(int sockfd,struct epoll_event* event)
    {
        if(epoll_ctl(_epfd,EPOLL_CTL_ADD,sockfd,event)==-1)
        {
            lg(FATAL,"epoll add fail");
        }
    }
    void Mod(int sockfd,struct epoll_event* event)
    {
        if(epoll_ctl(_epfd,EPOLL_CTL_MOD,sockfd,event)==-1)
        {
            lg(FATAL,"epoll mod fail");
        }
    }
    void Del(int sockfd)
    {
        if(epoll_ctl(_epfd,EPOLL_CTL_DEL,sockfd,nullptr)==-1)
        {
            lg(FATAL,"epoll del fail");
        }
    }
    int Wait(struct epoll_event* revs,int timeout)
    {
        int n = epoll_wait(_epfd,revs,MAXSIZE,timeout);
        return n;
    }
    ~Epoll(){}
private:
int _epfd;
};
#endif